<template>
  <div class="app-container">
    <!--用户数据-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单号">
        <el-input v-model="queryParams.houseInspectionId" placeholder="请输入单号" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="房间">
        <el-input v-model="queryParams.fullAddress" placeholder="请输入房间" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="queryParams.inspectionType" placeholder="请选择分类" clearable style="width: 240px">
          <el-option v-for="item in dict.type.inspection_type" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="状态">
        <el-select v-model="queryParams.inspectionState" placeholder="请选择状态" clearable style="width: 240px">
          <el-option v-for="item in dict.type.inspection_state" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="验房员">
        <el-input v-model="queryParams.homeInspectorName" placeholder="请输入验房员" clearable style="width: 240px"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['enterprise:inspection:add']">新增</el-button>
      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="单号" align="center" key="houseInspectionId" prop="houseInspectionId"
        :show-overflow-tooltip="true" />
      <el-table-column label="房间" align="center" key="fullAddress" prop="fullAddress" width="120" />
      <el-table-column label="分类" align="center" key="inspectionType" prop="inspectionType" width="120">
        <template slot-scope="scope">
          <span><dict-tag :options="dict.type.inspection_type" :value="scope.row.inspectionType" /></span>
        </template>
      </el-table-column>
      <el-table-column label="预计开始时间" align="center" prop="scheduledTime" width="160">
        <template slot-scope="scope">
          <span>{{ formatDate(scope.row.scheduledTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="inspectionState">
        <template slot-scope="scope">
          <span><dict-tag :options="dict.type.inspection_state" :value="scope.row.inspectionState" /></span>
        </template>
      </el-table-column>
      <el-table-column label="结果" align="center" key="inspectionResult" prop="inspectionResult" width="120">
        <template slot-scope="scope">
          <span><dict-tag :options="dict.type.inspection_result" :value="scope.row.inspectionResult" /></span>
        </template>
      </el-table-column>
      <el-table-column label="验房员" align="center" key="homeInspectorName" prop="homeInspectorName" width="120" />
      <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['enterprise:user:edit']">编辑</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-info" @click="handleDetail(scope.row)"
            v-hasPermi="['enterprise:inspection:query']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-user" @click="handleAssign(scope.row)"
            v-hasPermi="['enterprise:inspection:edit']" v-if="scope.row.inspectionState == 1">指派人员</el-button>
          <el-button size="mini" type="text" icon="el-icon-user" @click="handleReplace(scope.row)"
            v-hasPermi="['enterprise:inspection:change']" v-if="scope.row.inspectionState == 2">更换人员</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['enterprise:inspection:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <add v-model="open" :title="title" @success="getList" />
    <detail v-model="detailVisible" :data="houseInspection" />
    <assign v-model="assignVisible" :data="houseInspection" @success="getList" />
    <replace v-model="replaceVisible" :data="houseInspection" @success="getList" />
  </div>
</template>

<script>
import add from './add.vue'
import detail from './detail.vue';
import assign from './assign.vue';
import replace from './replace.vue';

import { listInspection, deleteInspection } from '@/api/houseCleaning/inspection';

export default {
  name: "Index",
  dicts: ['inspection_state', 'inspection_result','inspection_type'],
  components: { add, detail, assign, replace },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //显示 详情
      detailVisible: false,
      //显示 指派人员
      assignVisible: false,
      //显示 更换人员
      replaceVisible: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      //用户id
      userId: undefined,
      //验房信息
      houseInspection: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fullAddress: undefined,
        inspectionType: undefined,
        inspectionState: undefined,
        homeInspectorName: undefined,
        houseInspectionId: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `用户编号`, visible: true },
        { key: 1, label: `用户名称`, visible: true },
        { key: 2, label: `用户昵称`, visible: true },
        { key: 3, label: `部门`, visible: true },
        { key: 4, label: `手机号码`, visible: true },
        { key: 5, label: `状态`, visible: true },
        { key: 6, label: `创建时间`, visible: true }
      ],
      //验房分类列表
      // inspectionTypeList: [
      //   { label: '日常检查', value: 1 },
      //   { label: '换退验房', value: 2 },
      // ],
      //状态列表
      // inspectionStateList: [
      //   { label: '待指派', value: 1 },
      //   { label: '已指派', value: 2 },
      //   { label: '已完成', value: 3 },
      // ],
      // inspectionResultList: [
      //   { label: '正常', value: 1 },
      //   { label: '损坏', value: 2 },
      // ],
    };
  },
  computed: {
    // 分类文本
    // inspectionTypeText() {
    //   return (value) => {
    //     if(!value) return ''
    //     let obj = this.inspectionTypeList.find(item => item.value == value)
    //     return obj ? obj.label : ''
    //   }
    // },
    // //状态文本
    // inspectionStateText() {
    //   return (value) => {
    //     if(!value) return ''
    //     let obj = this.inspectionStateList.find(item => item.value == value)
    //     return obj ? obj.label : ''
    //   }
    // },
    // inspectionResultText() {
    //   return (value) => {
    //     if(!value) return ''
    //     let obj = this.inspectionResultList.find(item => item.value == value)
    //     console.log('obj',obj,value);
    //     return obj ? obj.label : ''
    //   }
    // }
  },
  watch: {
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listInspection(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        houseInspectionId: undefined,
        fullAddress: undefined,
        inspectionType: undefined,
        inspectionState: undefined,
        homeInspectorName: undefined
      },
        this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "新增";
    },
    handleDetail(row) {
      this.houseInspection = {...row}
      this.detailVisible = true
    },
    // 人员指派
    handleAssign(row) {
      this.houseInspection = {...row}
      this.assignVisible = true
    },
    // 更换人员
    handleReplace(row) {
      this.houseInspection = {...row}
      this.replaceVisible = true
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.houseInspectionId || this.ids;
      this.$modal.confirm('确定删除数据？').then(function () {
        return deleteInspection(Ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
  }
};
</script>

<style lang="scss" scoped></style>
